import App from './App'
import request from './request.js'


// 接口请求
Vue.prototype.$api = request


//跳转
Vue.prototype.onskipTab = function(url = '', callback = () => {}) {
        uni.switchTab({
            url:url
        })
}
//跳转
Vue.prototype.onskip = function(url = '', callback = () => {}) {
    uni.navigateTo({
        url: url
    })
}
// 回退上一步
Vue.prototype.back = function(url = '', callback = () => {}) {
    uni.navigateBack({delta:1})
}
// 图片
Vue.prototype.getImgUrl=function(url){
	if(url && url.indexOf('http')==-1){
		return this.$api.imgUrl+url
	}else{
		return url
	}
}
//图片预览 
Vue.prototype.prew=function(img){
	let imgs=[]
	if(	img.indexOf('http')==-1){
		img=this.$api.imgUrl+img
	}else{
		return img
	}
	imgs.push(img)
	uni.previewImage({
		// 预览图片  图片路径必须是一个数组 => ["http://192.168.100.251:8970/6_1597822634094.png"]
		urls: imgs,
		count: 1,
		longPressActions: {
			//长按保存图片到相册
			itemList: ['保存图片','识别二维码'],
			success: res => {
				uni.getImageInfo({
					src:imgs[res.index],
					success:data=>{
						uni.saveImageToPhotosAlbum({
							//保存图片到相册
							filePath: data.path,
							success: function() {
								uni.showToast({ icon: 'success', title: '保存成功' });
							},
							fail: err => {
								uni.showToast({ icon: 'none', title: '保存失败，请重新尝试' });
							}
						});
					}
				})
				console.log(data);
				
			},
			fail: err => {
				console.log(err.errMsg);
			}
		}
	});
}

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
// main.js
import uView from "uview-ui";
Vue.use(uView);
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif